package com.slg.android.manyanime.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.slg.android.manyanime.CartoonCategoryDetailsActivity;
import com.slg.android.manyanime.R;
import com.slg.android.manyanime.bean.CartoonCategory;
import com.slg.android.manyanime.bean.CartoonGroup;
import com.slg.android.manyanime.view.FullGridView;

import java.util.List;

/**
 * Created by Thinkpad on 2015/3/12.
 */
public class CartoonGroupAdapter extends BaseAdapter {

    private Context context;

    private List<CartoonGroup> data;
    //选中的种类
    private List<CartoonCategory> selectedCategorys = null;

    private String groupName;

    public CartoonGroupAdapter(Context context, List<CartoonGroup> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = null;
        if (convertView != null) {
            view = convertView;
        } else {
            view = inflater.inflate(R.layout.item_cartoon_category, parent, false);
        }
        ViewHolder viewHolder = (ViewHolder) view.getTag();
        if (viewHolder == null) {
            viewHolder = new ViewHolder();
            viewHolder.groupName = (TextView) view.findViewById(R.id.item_cartoon_category_groupname);
            viewHolder.cateGrid = (FullGridView) view.findViewById(R.id.item_cartoon_category_gridview);

            view.setTag(viewHolder);
        }
        groupName = data.get(position).getGroup();

        viewHolder.groupName.setText(groupName);//名称

        selectedCategorys = data.get(position).getCategories();

        viewHolder.cateGrid.setAdapter(
                new CartoonGroupInnerAdapter(context, selectedCategorys));

        viewHolder.cateGrid.setTag(groupName);

        return view;
    }



    public class ViewHolder {
        public TextView groupName;
        public GridView cateGrid;

    }
}
